home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
cgraphix
/
graphix.c
< prev
next >
Wrap
Text File
|
1986-05-12
|
4KB
|
194 lines
/* «RM120»«PL99999»«TS4,8,12,16,20,24,28,32,36,40,44,48,52,56,60,64,68,72,76» */
#include <stdio.h>
#define EXTERN extern
#include <typedef.h>
#define IBMPCjr 0
#define IBMCGA 1
#define IBMEGA 2
#define NoDisplay 3
extern unsigned seg();
int HardwarePresent()
{
int i, EquipFlag;
char Info, EGASwitch;
int HP;
struct regval regs;
HP = FALSE;
DisplayType = NoDisplay;
sysint(0x11, ®s, ®s);
EquipFlag = regs.ax;
regs.ax = 0x1200;
regs.bx = 0x0010;
sysint(0x10, ®s, ®s);
EGASwitch = regs.cx & 0x0ff;
Info = (regs.bx >> 16);
if (peek(0xfffe, 0xf000) == 0x0fd) {/* «MDBU»PCjr«MDNM» */
MinForeground = 0; /* Actually only 0 and 15 are valid */
MaxForeground = 15;
MinBackground = 0;
MaxBackground = 15;
DisplayType = IBMPCjr;
HP = TRUE;
}
else if (((EquipFlag & 52) == 0 ||
(EquipFlag & 52) == 16 ||
(EquipFlag & 52) == 32) &&
Info == 0) { /* «MDBU»EGA present, active, and in color«MDNM» */
MinForeground = 0;
MaxForeground = 15;
MinBackground = 0;
MaxBackground = 15;
DisplayType = IBMEGA;
HP = TRUE;
}
if (!HP)
if (((EquipFlag & 48) == 16 || (EquipFlag & 48) == 32) || /* «MDBU»CGA«MDNM» */
((EquipFlag & 52) == 4 && /* «MDBU»EGA present but not active«MDNM» */
(EGASwitch == 4 || EGASwitch == 5 || EGASwitch == 10 ||
EGASwitch == 11))) { /* «MDBU»EGA is mono, CGA for color«MDNM» */
MinForeground = 0;
MaxForeground = 15;
MinBackground = 0;
MaxBackground = 0;
DisplayType = IBMCGA;
HP = TRUE;
}
return(HP);
}
int AllocateRAMScreen()
{
extern char *calloc();
char *screen;
if (NULL == (screen = calloc(2 * ScreenSizeGlb + 16, 1)))
return(-1); /* not enough memory available for a */
/* RAM screen */
while (ofs(screen) != 0) /* Make absolutely certain that */
screen++; /* ScreenGlb is on a segment boundary! */
ScreenGlb = seg(screen);
return(0);
}
void LeaveGraphic()
{
struct regval regs;
regs.ax = SaveStateGlb;
sysint(0x10, ®s, ®s);
GrafModeGlb = FALSE;
}
void SetIBMPalette(PaletteNumber, Color)
int PaletteNumber, Color;
{
struct regval regs;
if (PaletteNumber != 2) {
regs.ax = 0x0B00;
regs.bx = PaletteNumber * 256 + Color;
}
else {
regs.ax = 0x1000;
regs.bx = Color * 256 + 1;
}
sysint(0x10, ®s, ®s);
}
void SetForegroundColor(Color)
int Color;
{
switch (DisplayType) {
case IBMPCjr:
SetIBMPalette(1,1-(Color & 1));
break;
case IBMCGA:
SetIBMPalette(0,Color);
break;
case IBMEGA:
SetIBMPalette(2,Color);
break;
}
ForegroundColorGlb = Color;
}
void SetBackgroundColor(Color)
int Color;
{
switch (DisplayType) {
case IBMPCjr:
case IBMEGA:
SetIBMPalette(0,Color);
break;
}
if (DisplayType == IBMEGA)
SetIBMPalette(2,ForegroundColorGlb);
}
void EnterGraphic()
{
struct regval regs;
int FontFile;
if (!FontLoaded) {
if (0 > (FontFile = open("8x8.fon", BREAD))) {
fprintf(stderr, "Font file cannot be opened.\n");
inkey();
memset(Font, 0, 256 * 8);
}
else {
read(FontFile, Font, 256 * 8);
close(FontFile);
}
FontLoaded = TRUE;
}
regs.ax = 0x0f00;
sysint(0x10, ®s, ®s);
if (((regs.ax & 0xff) < 4) || (SaveStateGlb == 10))
SaveStateGlb = regs.ax & 0xff;
regs.ax = 0x0006;
sysint(0x10, ®s, ®s);
SetForegroundColor(MaxForeground);
GrafModeGlb = TRUE;
}
void SetBackground8(Background)
BackgroundArray Background;
{
int i, j;
for (i = Y1RefGlb; i <= Y2RefGlb; i++) {
for (j = 0; j < X2RefGlb-X1RefGlb+1; j++)
pokeb(BaseAddress(i) + X1RefGlb + j, GrafBase, Background[i & 7]);
}
}
void SetBackground(byt)
unsigned char byt;
{
int i;
for (i = Y1RefGlb; i <= Y2RefGlb; i++)
filblock(BaseAddress(i)+X1RefGlb, GrafBase, byt, X2RefGlb-X1RefGlb+1);
}